import { request } from '@/service/request';

// ---------- Task Begin ----------

/** get task page */
export function fetchGetCjTaskPage(params?: Api.Sampling.TaskSearchParams) {
  return request<Api.Sampling.TaskList>({
    url: '/cj_task/page',
    method: 'GET',
    params
  });
}

/** add task info */
export function fetchAddCjTask(data: Api.Sampling.TaskEdit) {
  return request<boolean>({
    url: '/cj_task/',
    method: 'POST',
    data
  });
}

/** update task info */
export function fetchUpdateCjTask(data: Api.Sampling.TaskEdit) {
  return request<boolean>({
    url: '/cj_task/',
    method: 'PUT',
    data
  });
}

/** edit delete task */
export function fetchDeleteCjTask(data: Api.Common.DeleteParams) {
  return request<boolean>({
    url: '/cj_task/',
    method: 'DELETE',
    data
  });
}

export function fetchCjTaskDownloadTemplate() {
  return request<string>({
    url: `/cj_task/download_template`,
    method: 'GET'
  });
}

export function fetchCjTaskUploadData(data: FormData) {
  return request<string>({
    url: '/cj_task/upload_data',
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  });
}

export function fetchGetCjTaskList(params: Api.Sampling.CjTask.ListParams) {
  return request<Api.Sampling.Record[]>({
    url: '/cj_task/list',
    method: 'GET',
    params
  });
}

// 首次进入定位
export function getLocation() {
  return request<Api.Sampling.CjRecordFirInfo.RecordInfo>({
    url: `/cj_task/mb_long_lat`,
    method: 'GET'
  });
}
